//
//  MHRedPacketOrderRecordCell.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/11/4.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHRedPacketOrderRecordCell.h"
#import "MHCommonItemViewModel.h"
#import "MHRedPacketOrderRecordItemViewModel.h"
#import "MHRedHistoryRecord.h"
@interface  MHRedPacketOrderRecordCell()

//正文
@property (nonatomic, readwrite, weak) YYLabel *contentLable;

//封面
@property(nonatomic, strong) UIImageView *coverImageView;

//时间和来源
@property(nonatomic, strong) YYLabel *timeAndSourceLabel;

//金额

@property(nonatomic, strong) YYLabel *amountLable;

@property(nonatomic, strong) UIImageView *splitImage;

@end

@implementation MHRedPacketOrderRecordCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _setupSubViews];
    }
    return self;
    
}

- (void)_setupSubViews
{
    
    UIImageView * imageView = [UIImageView new];
    [self addSubview:imageView];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.masksToBounds = YES;
    self.coverImageView = imageView;
    
    YYLabel *contentLable = [[YYLabel alloc] init];
    contentLable.backgroundColor = self.contentView.backgroundColor;
    /// 垂直方向顶部对齐
    contentLable.textVerticalAlignment = YYTextVerticalAlignmentTop;
    /// 异步渲染和布局
    contentLable.displaysAsynchronously = NO;
    /// 利用textLayout来设置text、font、textColor...
    contentLable.ignoreCommonProperties = YES;
    contentLable.fadeOnAsynchronouslyDisplay = NO;
    contentLable.fadeOnHighlight = NO;
    contentLable.preferredMaxLayoutWidth = MHMomentCommentViewWidth();
    [self.contentView addSubview:contentLable];
    self.contentLable = contentLable;
    
    
    /// 创建时间和圈子
    YYLabel *timeAndSourceLabel = [[YYLabel alloc] init];
    timeAndSourceLabel.backgroundColor = self.contentView.backgroundColor;
    timeAndSourceLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    /// 异步渲染和布局
    timeAndSourceLabel.displaysAsynchronously = NO;
    /// 利用textLayout来设置text、font、textColor...
    timeAndSourceLabel.ignoreCommonProperties = YES;
    timeAndSourceLabel.fadeOnAsynchronouslyDisplay = NO;
    timeAndSourceLabel.fadeOnHighlight = NO;
    [self.contentView addSubview:timeAndSourceLabel];
    self.timeAndSourceLabel = timeAndSourceLabel;
    
    
    YYLabel *amountLable = [[YYLabel alloc] init];
    amountLable.backgroundColor = self.contentView.backgroundColor;
    amountLable.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    /// 异步渲染和布局
    amountLable.displaysAsynchronously = NO;
    /// 利用textLayout来设置text、font、textColor...
    amountLable.ignoreCommonProperties = YES;
    amountLable.fadeOnAsynchronouslyDisplay = NO;
    amountLable.fadeOnHighlight = NO;
    [self.contentView addSubview:amountLable];
    self.amountLable = amountLable;
    
    UIImageView *splitImage =[UIImageView new];
    [self addSubview:splitImage];
    self.splitImage = splitImage;
    splitImage.backgroundColor = MHColorFromHexString(@"#E8E8E8");
}



-(void)bindViewModel:(MHRedPacketOrderRecordItemViewModel *)viewModel
{
    
    MHRedHistoryRecord *record = viewModel.model;
    self.coverImageView.frame = viewModel.coverImageFrame;
    
    self.contentLable.textLayout = viewModel.contentLableLayout;
    self.contentLable.frame = viewModel.contentFrame;
    
    self.timeAndSourceLabel.textLayout = viewModel.timeAndSourceLayout;
    self.timeAndSourceLabel.frame = viewModel.timeAndSourceFrame;
    self.amountLable.textLayout = viewModel.amountLayout;
    self.amountLable.frame = viewModel.amountFrame;
    
    [self.coverImageView yy_setImageWithURL:[NSURL URLWithString:record.coverUrl] options:nil];
    

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.splitImage.frame = CGRectMake(0,self.height, MH_SCREEN_WIDTH, 1);
}

@end
